<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2022/11/3
  Time: 19:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="${pageContext.request.contextPath}/assets/images/favicon.png" type="image/png">
    <title>秒杀活动列表</title>

    <!-- BEGIN PAGE LEVEL STYLES -->
    <link href="${pageContext.request.contextPath}/assets/plugins/datatables/css/jquery.dataTables.min.css"
          rel="stylesheet" type="text/css"/>
    <link href="${pageContext.request.contextPath}/assets/plugins/datatables/css/jquery.dataTables-custom.css"
          rel="stylesheet" type="text/css"/>
    <!-- END PAGE LEVEL STYLES -->
    <link href="${pageContext.request.contextPath}/assets/css/icons.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/assets/css/bootstrap.min.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/assets/css/style.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/assets/css/responsive.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]-->
    <script src="${pageContext.request.contextPath}/js/html5shiv.min.js"></script>
    <script src="${pageContext.request.contextPath}/js/respond.min.js"></script>
    <!--[endif]-->

    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .el-card__body {
            padding: 20px;
            background-color: white;
            font-size: 14px;
            border: solid 1px rgba(0,0,0,0.2);
        }

        .el-table th {
            white-space: nowrap;
            overflow: hidden;
            user-select: none;
            padding: 12px 0;
            min-width: 0;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
        }

        .el-table--border th {
            border-right: 1px solid #ebeef5;
        }


        .el-table--border td {
            border-bottom: 1px solid #ebeef5;
        }


        label {
            display: inline-block;
            max-width: 100%;
            margin-bottom: 5px;
            font-weight: 700;
        }

        .table-responsive {
            min-height: .01%;
            overflow-x: auto;
        }

        /*窗口*/
        .window {
            padding-top: 20px;
            padding-bottom: 30px;
            border-radius: 2px;
            box-shadow: 0 0 3px grey;
            background-color: #fff;
            position: fixed;
            left: 0;
            top: 150px;
            display: none;
            z-index: 10;
        }

        @media (max-width: 992px) {
            .window form .form-control {
                margin-bottom: 20px;
            }
        }

        @media (min-width: 992px) {
            .window form .opt {
                text-align: right;
            }
        }

        /*中间层*/
        .not-active {
            position: fixed;
            top: 0;
            left: 0;
            bottom: 0;
            right: 0;
            background-color: rgba(0, 0, 0, .5);
            z-index: 5;
        }

        #shade {
            display: none;
        }

        /*关闭弹窗按钮*/
        .window #close-window {
            border: 0;
            outline: none;
            background-color: #fff;
        }

        .window #close-window .btn:hover {
            color: deepskyblue;
        }

        .btn-default {
            border: 0;
            outline: 0;
            background-color: #fff;
            color: rgb(14, 144, 210);
        }

        .btn-default:hover, .btn-default:focus, .btn-default:active:focus, .btn-default:after {
            color: rgb(14, 144, 210);
            background-color: #fff;
        }

        .btn:focus, .btn:active:focus {
            outline: none;
            box-shadow: none;
        }

        /*分页相关*/
        .pagination > li > button {
            position: relative;
            float: left;
            padding: 6px 12px;
            margin-left: -1px;
            line-height: 1.42857143;
            color: #337ab7;
            text-decoration: none;
            background-color: #fff;
            border: 1px solid #eee;
        }

        .pagination > .disabled > button, .pagination > .disabled > button:focus, .pagination > .disabled > button:hover {
            color: #777;
            cursor: not-allowed;
            background-color: #fff;
            border-color: #eee
        }

        .pagination > li > select, .pagination > li > input, .pagination > li > button {
            position: relative;
            float: left;
            padding: 6px 12px;
            margin-left: -1px;
            line-height: 1.42857143;
            text-decoration: none;
            background-color: #fff;
            border: 1px solid #ddd;
        }
        .pagination > li > input {
            outline: none;
        }
        .pagination > li > span:hover {
            background-color: #fff;
        }
    </style>

</head>

<body class="sticky-header">

<!--Start left side Menu-->
<jsp:include page="../inc/left.jsp"/>
<!--End left side menu-->


<!-- main content start-->
<div class="main-content">

    <!-- header section start-->
    <jsp:include page="../inc/header.jsp"/>
    <!-- header section end-->

    <div class="wrapper" style="background-color:rgb(238, 238, 238);">

        <!--Start Page Title-->
        <div class="page-title-box">
            <p class="page-title" style="color: black">秒杀活动列表<small style="font-size: 14px;">&emsp;胡松</small></p>
            <ol class="breadcrumb">
                <li>
                    <a href="#">首页</a>
                </li>
                <li>
                    <a href="#">营销</a>
                </li>
                <li class="active">
                    秒杀活动列表
                </li>
            </ol>
            <div class="clearfix"></div>
        </div>
        <!--End Page Title-->

        <div class="el-card__body col-sm-12" style="margin-bottom: 15px">
            <i class="fa fa-search" aria-hidden="true"></i> <span>筛选搜索</span>
            <div style="margin-top: 15px;">
                <form class="el-form el-form--inline form-group"
                      action="${pageContext.request.contextPath}/sell/flashPromotion/list" method="get">
                    <div class="el-form-item el-form-item--small">
                        <div class="el-form-item__content">
                            <div class="input-width">
                                <div class="col-sm-1">
                                    <label class="" style="width: 70px;padding-top: 7px">活动名称：</label>
                                </div>
                                <div class="col-sm-3">
                                    <input id="title-search" type="text" autocomplete="off" name="title"
                                           placeholder="活动名称"
                                           class="el-input__inner form-control" value="${search}">
                                </div>
                                <div class="col-sm-4 col-sm-offset-4">
                                    <button type="submit" class="btn btn-info"
                                            style="float: right;">
                                        <span>查询搜索</span>
                                    </button>
                                    <button id="reset-search" type="button" class="btn btn-white"
                                            style="float: right; margin-right: 15px;">
                                        <span>重置</span>
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>

        <div class="el-card__body col-sm-12">
            <i class="fa fa-file-text-o" aria-hidden="true"></i>
            <span style="font-size: 16px;">数据列表</span>
            <div style="float: right">
                <button id="btn-add" type="button" class="btn btn-info"
                        style="margin-right: 20px;">
                    <span>添加活动</span>
                </button>
                <a id="btn-list" href="${pageContext.request.contextPath}/sell/flashPromotionSession/list"
                   class="btn btn-info">
                    <span>秒杀时间段列表</span>
                </a>
            </div>
        </div>


        <%--Start 弹窗 --%>
        <div id="shade" class="not-active"></div>
        <div class="window row col-sm-5 col-sm-offset-4 col-md-5 col-md-offset-4 col-lg-5 col-lg-offset-4">
            <div class="col-lg-4 col-md-4 col-sm-4" style="margin-bottom: 20px">
                <h4>编辑活动</h4>
            </div>
            <button id="close-window"
                    class="btn btn-default col-lg-1 col-lg-offset-7 col-md-1 col-md-o7 col-sm-1 col-sm-offset-7">
                <i class="ion-close"></i>
            </button>
            <div class="col-sm-12 col-md-12 col-lg-10 col-lg-offset-1">
                <form action="${pageContext.request.contextPath}/sell/flashPromotion/save" method="post"
                      class="form-group">
                    <div class="col-sm-12 col-md-12 col-lg-11">
                        <div class="col-sm-12 col-md-12 col-lg-12" style="display: none">
                            <div class="opt col-sm-12 col-md-4 col-lg-4">
                                <label for="id">ID：</label>
                            </div>
                            <div class="col-sm-12 col-md-8 col-lg-8">
                                <input id="id" name="id" class="form-control">
                            </div>
                            <div class="col-sm-12 col-md-12 col-lg-12" style="display: none">
                                <input name="page" class="form-control" value="${pageInfo.pageNum}">
                            </div>
                            <div class="col-sm-12 col-md-12 col-lg-12" style="display: none">
                                <input name="size" class="form-control" value="${pageInfo.pageSize}">
                            </div>
                        </div>

                        <div class="opt col-sm-12 col-md-4 col-lg-4">
                            <label for="title">活动名称：</label>
                        </div>
                        <div class="col-sm-12 col-md-8 col-lg-8">
                            <input id="title" name="title" class="form-control" required>
                        </div>
                        <br>
                        <br>
                        <br>
                        <div class="opt col-sm-12 col-md-4 col-lg-4">
                            <label for="start">开始时间：</label>
                        </div>
                        <div class="col-sm-12 col-md-8 col-lg-8">
                            <input id="start" type="date" name="startDate" class="form-control" required>
                        </div>
                        <br>
                        <br>
                        <br>
                        <div class="opt col-sm-12 col-md-4 col-lg-4">
                            <label for="end" class="text-right">结束时间：</label>
                        </div>
                        <div class="col-sm-12 col-md-8 col-lg-8">
                            <input id="end" type="date" name="endDate" class="form-control" required>
                        </div>
                        <br>
                        <br>
                        <br>
                        <div class="opt col-sm-12 col-md-4 col-lg-4">
                            <label for="status">上线/下线：</label>
                        </div>
                        <div class="col-sm-12 col-md-8 col-lg-8">
                            <section id="status" style="margin-bottom: 20px">
                                <input id="on" type="radio" value="1" name="status"> 上线 &emsp;&emsp;
                                <input id="off" type="radio" value="0" name="status"> 下线
                            </section>
                        </div>
                        <br>
                        <br>
                        <br>
                        <div class="col-sm-1 col-sm-offset-2 col-md-1 col-md-offset-3">
                            <input type="submit" value="确认" class="btn btn-success">
                        </div>
                        <div class="col-sm-1 col-sm-offset-2 col-md-1 col-md-offset-2">
                            <button id="reset-edit" type="button" class="btn btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>

        </div>
        <%--End 弹窗 --%>


        <!--Start row-->
        <div class="row">
            <div class="col-md-12">
                <div class="white-box" style="border: solid 1px rgba(0,0,0,0.2); margin-top: 15px">
                    <br>
                    <div class="table-responsive">
                        <div id="example_wrapper" class="dataTables_wrapper">
                            <table id="example" class="table table-bordered">
                                <thead>
                                <tr>
                                    <th class="text-center"><input id="all-select" type="checkbox"></th>
                                    <th class="text-center">编号</th>
                                    <th class="text-center">活动标题</th>
                                    <th class="text-center">活动状态</th>
                                    <th class="text-center">开始时间</th>
                                    <th class="text-center">结束时间</th>
                                    <th class="text-center">上线/下线</th>
                                    <th class="text-center">操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                <c:forEach begin="0" end="${pageInfo.size - 1}" var="i">
                                    <tr class="flash-data">
                                        <td class="text-center"><input class="check-one" type="checkbox"></td>
                                        <td class="text-center">${pageInfo.list.get(i).id}</td>
                                        <td class="text-center">${pageInfo.list.get(i).title}</td>
                                        <td class="text-center active-status">

                                        </td>
                                        <td class="text-center start-date"><fmt:formatDate
                                                value="${pageInfo.list.get(i).startDate}" pattern="yyyy-MM-dd"/></td>

                                        <td class="text-center end-date"><fmt:formatDate
                                                value="${pageInfo.list.get(i).endDate}"
                                                pattern="yyyy-MM-dd"/></td>
                                        <td class="text-center">
                                            <button id="status-${pageInfo.list.get(i).id}" class="btn btn-default" onclick="change(${pageInfo.list.get(i).id})">
                                                <i class="fa fa-2x fa-toggle-${pageInfo.list.get(i).status==1?'on':'off'}"></i>
                                            </button>
                                        </td>
                                        <td class="handle text-center">
                                            <a href="${pageContext.request.contextPath}/sell/flashProductRelation/list?flashPromotionId=${pageInfo.list.get(i).id}"
                                               class="btn btn-success">设置商品</a>
                                            <button id="btn-update" class="btn btn-info"
                                                    onclick="update(${pageInfo.list.get(i).id})">编辑
                                            </button>
                                            <button id="btn-delete" class="btn btn-danger"
                                                    onclick="del(${pageInfo.list.get(i).id})">删除
                                            </button>
                                        </td>
                                    </tr>
                                </c:forEach>
                                </tbody>
                            </table>
                            <form action="${pageContext.request.contextPath}/sell/flashPromotion/list" method="get" class="form-group">
                                <nav aria-label="..." style="text-align: left">
                                    <ul class="pagination">
                                        <li><span style="border-radius: 0">共 ${pageInfo.total} 条数据</span></li>
                                        <li>
                                            <select id="pageSize" name="size" style="outline: none; padding: 5.5px 12px">
                                                <option value="10" ${pageInfo.pageSize==10?"selected":""}>10条/页</option>
                                                <option value="20" ${pageInfo.pageSize==20?"selected":""}>20条/页</option>
                                                <option value="30" ${pageInfo.pageSize==30?"selected":""}>30条/页</option>
                                                <option value="50" ${pageInfo.pageSize==50?"selected":""}>50条/页</option>
                                            </select>
                                        </li>
                                        <%--Start 上一页按钮--%>
                                        <li class="${pageInfo.pageNum == 1 ? "disabled":""}">
                                            <c:choose>
                                                <c:when test="${pageInfo.pageNum == 1}">
                                                    <button type="button" aria-label="Next">
                                                        上一页</button>
                                                </c:when>
                                                <c:when test="${pageInfo.pageNum gt 1}">
                                                    <button id="prev" type="button" aria-label="Previous">
                                                        上一页</button>
                                                </c:when>
                                            </c:choose>
                                        </li>
                                        <%--End 上一页按钮--%>
                                        <%--Start 页码--%>
                                        <c:forEach begin="1" end="${pageInfo.pages}" var="i">
                                            <li class="${pageInfo.pageNum == i ? "active":""}">
                                                <a href="${pageContext.request.contextPath}/sell/flashPromotion/list?page=${i}&size=${pageInfo.pageSize}">
                                                        ${i} <span class="sr-only">(current)</span>
                                                </a>
                                            </li>
                                        </c:forEach>
                                        <%--End 页码--%>
                                        <%--Start 下一页按钮--%>
                                        <li class="${pageInfo.pageNum == pageInfo.pages ? "disabled":""}">
                                            <c:choose>
                                                <c:when test="${pageInfo.pageNum == pageInfo.pages}">
                                                    <button type="button" aria-label="Next">
                                                        下一页</button>
                                                </c:when>
                                                <c:when test="${pageInfo.pageNum lt pageInfo.pages}">
                                                    <button id="next" type="button" aria-label="Next">
                                                        下一页</button>
                                                </c:when>
                                            </c:choose>
                                        </li>
                                        <%--End 下一页按钮--%>

                                        <%-- Start 页码跳转 --%>
                                        <li><span>前往</span></li>
                                        <li><input id="target" name="page" style="width: 40px;text-align: center"></li>
                                        <li><span>页</span></li>
                                        <li>
                                            <button id="goto" type="button" class="btn btn-default"
                                                    style="text-align: center;">》
                                            </button>
                                        </li>
                                        <%-- End 页码跳转 --%>
                                    </ul>
                                </nav>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--End row-->
    </div>

    <!--Start  Footer -->
    <%@include file="../inc/footer.jsp" %>
    <!--End footer -->

</div>
<!--End main content -->


<!--Begin core plugin -->
<script src="${pageContext.request.contextPath}/assets/js/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/assets/plugins/moment/moment.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/jquery.slimscroll.js "></script>
<script src="${pageContext.request.contextPath}/assets/js/jquery.nicescroll.js"></script>
<script src="${pageContext.request.contextPath}/assets/js/functions.js"></script>
<!-- End core plugin -->

<!--Begin Page Level Plugin-->
<%--<script src="${pageContext.request.contextPath}/assets/plugins/datatables/js/jquery.dataTables.min.js"></script>--%>
<script src="${pageContext.request.contextPath}/assets/pages/table-data.js"></script>
<!--End Page Level Plugin-->

<script>
    // 状态修改
    function change(id) {
        $.ajax({
            type: 'post',
            url: '${pageContext.request.contextPath}/sell/flashPromotion/change',
            data: {id: id},
            success: function (response) {
                if (response.status == 1) {
                    $("#status-"+response.id).html('<i class="fa fa-2x fa-toggle-on"></i>')
                }else {
                    $("#status-"+response.id).html('<i class="fa fa-2x fa-toggle-off"></i>')
                }
            }
        })
    }

    // 添加新活动时
    $("#btn-add").click(function () {
        openWindow();
        $("#id").val(null);
        $("#start").val(null);
        $("#end").val(null);
        $("#title").val(null);
        $("#on").prop("checked", "checked");
    });

    // 修改活动时回显
    function update(id) {
        openWindow()
        $.ajax({
            type: 'get',
            url: '${pageContext.request.contextPath}/sell/flashPromotion/queryById/' + id,
            success: function (response) {
                $("#id").val(response.data.id);
                $("#title").val(response.data.title);
                $("#start").val(dateFormat(response.data.startDate));
                $("#end").val(dateFormat(response.data.endDate));
                if (response.data.status == 1) {
                    $("#on").prop("checked", "checked");
                } else {
                    $("#off").prop("checked", "checked");
                }
            }
        })
    }

    // 删除确认
    function del(id) {
        let sure = confirm("确定删除吗？");
        if (sure) {
            console.info("确认删除")
            location.href = "${pageContext.request.contextPath}/sell/flashPromotion/delete/" + id + "?page=1" + "&size=" + ${pageInfo.pageSize};
        }
    }

    // 全选全不选
    $("#all-select").click(function () {
        $(".check-one").prop("checked", this.checked);
    })

    // 日期格式化
    function dateFormat(date) {
        let year = new Date(date).getFullYear();
        let month = new Date(date).getMonth() + 1;
        if (month < 10) {
            month = "0" + month;
        }
        let day = new Date(date).getDate();
        if (day < 10) {
            day = "0" + day;
        }
        return year + "-" + month + "-" + day;
    }

    // 弹出表单输入窗口
    function openWindow() {
        $("#shade").fadeIn(300);
        $(".window").fadeIn(300);
    }

    // 关闭窗口
    $("#close-window").click(function () {
        $(".window").fadeOut(100);
        $("#shade").fadeOut(100);
    })

    // 重置编辑表单
    $("#reset-edit").click(function () {
        $("#start").val("");
        $("#end").val("");
        $("#title").val("");
        $("#on").prop("checked", "checked");
    })
    // 重置搜索框
    $("#reset-search").click(function () {
        $("#title-search").val("");
        location.href = "${pageContext.request.contextPath}/sell/flashPromotion/list";
    })

    // 上一页
    $("#prev").click(function () {
        let size = $("#pageSize").val();
        location.href = "${pageContext.request.contextPath}/sell/flashPromotion/list?page=${pageInfo.pageNum-1}" + "&size=" + size;
    })
    // 下一页
    $("#next").click(function () {
        let size = $("#pageSize").val();
        location.href = "${pageContext.request.contextPath}/sell/flashPromotion/list?page=${pageInfo.pageNum + 1}" + "&size=" + size;
    })

    // 每页显示条数改变
    $("#pageSize").change(function () {
        let size = $(this).val();
        location.href = "${pageContext.request.contextPath}/sell/flashPromotion/list?page=1&size=" + size;
    })

    // 跳转指定页数
    $("#goto").click(function () {
        let target = $("#target").val();
        let pages = ${pageInfo.pages};
        console.info("前往" + target);
        console.info("总页数" + pages);
        if (target > pages) {
            target = pages;
        } else if (target < 1) {
            target = 1
        }
        location.href = '${pageContext.request.contextPath}/sell/flashPromotion/list?page=' + target + '&size=' + ${pageInfo.pageSize};

    })


    timeCheck();

    // 活动当前状态（已结束，未开始，进行中）
    function timeCheck() {
        $(".flash-data").each(function (i, j) {
            let startDate = $(j).children(".start-date").text();
            let endDate = $(j).children(".end-date").text();
            let now = new Date();
            let start = new Date(startDate);
            let end = new Date(endDate);
            if (now >= start && now <= end) {
                $(j).children(".active-status").text("正在进行中");
            } else if (now < start) {
                $(j).children(".active-status").text("未开始");
            } else {
                $(j).children(".active-status").text("已结束");
            }
        })

    }

</script>
</body>

</html>

